import { useUserStore } from '@/store/module/user'
import router from '@/router'

// 退出登录
export const isToken = (before?: () => void, after?: () => void) => {
  before && before()
  // 删除 token
  localStorage.removeItem('token')
  // 清空仓库
  const userStore = useUserStore()
  userStore.$reset()
  // 清空动态路由
  router.getRoutes().forEach((item) => {
    if (item.name && item.name !== 'login') {
      router.removeRoute(item.name)
    }
  })
  // 跳转到 login
  router.push('/login')
  after && after()
}
